/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufabc.edu.logica.nao.classicas.view;

import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JLabel;
import javax.swing.UIManager;

import net.sourceforge.jFuzzyLogic.FIS;
import net.sourceforge.jFuzzyLogic.FunctionBlock;

/**
 * 
 * @author davidson
 */
public class FramePrincipal extends javax.swing.JFrame {

	private static final String FILE_NAME_FCL = "lib/fcl/SistemaBombeio.fcl";

	private FIS fis;

	/**
	 * Creates new form FramePrincipal
	 */
	public FramePrincipal() {
		initComponents();
		fis = FIS.load(FILE_NAME_FCL, true);
		// this.setExtendedState(FramePrincipal.MAXIMIZED_BOTH);
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
			// UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			// UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch (Exception ex) {
			Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

	/**
	 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
	 * content of this method is always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        btnTODOS = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        labelImagem = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        resultBombaFundo = new javax.swing.JLabel();
        resultColunaHastes = new javax.swing.JLabel();
        resultBombeio = new javax.swing.JLabel();
        resultSistemaBombeio = new javax.swing.JLabel();
        imgPaletaCores = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jTextField2 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnBF = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jTextField3 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        btnCDH = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        btnUB = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        jLabel1.setText("Sistema para Classificação do Bombeamento de Petróleo");

        jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel2.setText("Entradas:");

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        btnTODOS.setText("Avaliar todos");
        btnTODOS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTODOSActionPerformed(evt);
            }
        });
        btnTODOS.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                avaliarButtonFocusGained(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel11.setText("Componentes:");

        labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_nenhum.png"))); // NOI18N

        jLabel12.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel12.setText("Classificações:");

        jLabel13.setText("Bomba de Fundo:");

        jLabel14.setText("Coluna de Hastes:");

        jLabel15.setText("Bombeio:");

        jLabel16.setText("Sistema de Bombeio:");

        resultBombaFundo.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        resultBombaFundo.setText("X");

        resultColunaHastes.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        resultColunaHastes.setText("X");

        resultBombeio.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        resultBombeio.setText("X");

        resultSistemaBombeio.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        resultSistemaBombeio.setText("X");

        imgPaletaCores.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/BarraCoresSmall.png"))); // NOI18N
        imgPaletaCores.setToolTipText("");

        jLabel17.setText("RUIM");

        jLabel18.setText("BOM");

        jLabel19.setText("ÓTIMO");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                nivelVazaoFocusGained(evt);
            }
        });

        jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                eficienciaVolumetricaFocusGained(evt);
            }
        });

        jLabel4.setText("Nível de Atendimento de Vazão [0.95..1.5]");

        jLabel3.setText("Eficiência Volumétrica [0..1]");

        btnBF.setText("Avaliar");
        btnBF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBFActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addContainerGap(40, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnBF))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBF))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jTextField3.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                grauUtilizacaoHastesFocusGained(evt);
            }
        });

        jLabel5.setText("Grau de Utilização de Hastes [0..1]");

        jTextField4.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                custosColunaHastesFocusGained(evt);
            }
        });

        jLabel6.setText("Custo da Coluna de Hastes [0.3..2.0]");

        btnCDH.setText("Avaliar");
        btnCDH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCDHActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnCDH))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCDH))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel7.setText("Peak de Torque [0..1]");

        jTextField5.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                peakTorqueFocusGained(evt);
            }
        });

        jLabel8.setText("Frequência de Bombeio [0..25]");

        jTextField6.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                frequenciaBombeioFocusGained(evt);
            }
        });

        jLabel9.setText("Carga Máxima [0..1]");

        jTextField7.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cargaMaxFocusGained(evt);
            }
        });

        jLabel10.setText("Carga Mínima [0..1]");

        btnUB.setText("Avaliar");
        btnUB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addGap(57, 57, 57))
                            .addComponent(jLabel8)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(3, 3, 3))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel9)
                                .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnUB))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnUB)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(jLabel1)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addComponent(labelImagem)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 714, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel12)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(btnTODOS, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(76, 76, 76)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel14)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(resultColunaHastes))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel13)
                                                .addGap(18, 18, 18)
                                                .addComponent(resultBombaFundo)))
                                        .addGap(139, 139, 139)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                .addComponent(jLabel15)
                                                .addGap(96, 96, 96)
                                                .addComponent(resultBombeio))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                .addComponent(jLabel16)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(resultSistemaBombeio)))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(imgPaletaCores)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel18)
                                    .addComponent(jLabel19)))))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 1044, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(48, 48, 48)
                        .addComponent(labelImagem))
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 528, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnTODOS, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(31, 31, 31)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel16)
                                            .addComponent(resultSistemaBombeio)))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel15)
                                        .addComponent(resultBombeio)))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel13)
                                        .addComponent(resultBombaFundo))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel14)
                                        .addComponent(resultColunaHastes))))))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel17)
                            .addGap(18, 18, 18)
                            .addComponent(jLabel18)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel19))
                        .addComponent(imgPaletaCores)))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnBFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBFActionPerformed
        FunctionBlock functionBlock = fis.getFunctionBlock(null);
        double ev = Double.valueOf(this.jTextField1.getText());
        functionBlock.setVariable("EV", ev); // Eficiência Volumétrica [0..1]
        double nav = Double.valueOf(this.jTextField2.getText());
        functionBlock.setVariable("NAV", nav); // Nível de Atendimento de Vazão [0.95..1.5]
        functionBlock.setVariable("UH", 0); // Grau de Utilização de Hastes [0..1]
        functionBlock.setVariable("CH", 0.3); // Custo da Coluna de Hastes [0.3..2.0]
        functionBlock.setVariable("PT", 0); // Peak de Torque [0..1]
        functionBlock.setVariable("FB", 0); // Frequência de Bombeio [0..25]
        functionBlock.setVariable("CMax", 0); // Carga Máxima [0..1]
        functionBlock.setVariable("CMin", 0); // Carga Mínima [0..1]

        functionBlock.evaluate();

        setResultLabel(functionBlock, this.resultBombaFundo, "BF");
    }//GEN-LAST:event_btnBFActionPerformed

    private void btnCDHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCDHActionPerformed
        FunctionBlock functionBlock = fis.getFunctionBlock(null);
        functionBlock.setVariable("EV", 0); // Eficiência Volumétrica [0..1]
        functionBlock.setVariable("NAV", 0.95); // Nível de Atendimento de Vazão [0.95..1.5]
        double uh = Double.valueOf(this.jTextField3.getText());
        functionBlock.setVariable("UH", uh); // Grau de Utilização de Hastes [0..1]
        double ch = Double.valueOf(this.jTextField4.getText());
        functionBlock.setVariable("CH", ch); // Custo da Coluna de Hastes [0.3..2.0]
        functionBlock.setVariable("PT", 0); // Peak de Torque [0..1]
        functionBlock.setVariable("FB", 0); // Frequência de Bombeio [0..25]
        functionBlock.setVariable("CMax", 0); // Carga Máxima [0..1]
        functionBlock.setVariable("CMin", 0); // Carga Mínima [0..1]

        functionBlock.evaluate();

        setResultLabel(functionBlock, this.resultColunaHastes, "CDH");
    }//GEN-LAST:event_btnCDHActionPerformed

    private void btnUBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUBActionPerformed
        FunctionBlock functionBlock = fis.getFunctionBlock(null);
        functionBlock.setVariable("EV", 0); // Eficiência Volumétrica [0..1]
        functionBlock.setVariable("NAV", 0.95); // Nível de Atendimento de Vazão [0.95..1.5]
        functionBlock.setVariable("UH", 0); // Grau de Utilização de Hastes [0..1]
        functionBlock.setVariable("CH", 0.3); // Custo da Coluna de Hastes [0.3..2.0]
        double pt = Double.valueOf(this.jTextField5.getText());
        functionBlock.setVariable("PT", pt); // Peak de Torque [0..1]

        double fb = Double.valueOf(this.jTextField6.getText());
        functionBlock.setVariable("FB", fb); // Frequência de Bombeio [0..25]

        double cMax = Double.valueOf(this.jTextField7.getText());
        functionBlock.setVariable("CMax", cMax); // Carga Máxima [0..1]

        double cMin = Double.valueOf(this.jTextField8.getText());
        functionBlock.setVariable("CMin", cMin); // Carga Mínima [0..1]

        functionBlock.evaluate();

        setResultLabel(functionBlock, this.resultBombeio, "UB");
    }//GEN-LAST:event_btnUBActionPerformed

	private void eficienciaVolumetricaFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_eficienciaVolumetricaFocusGained
		labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_bomba.png")));
	}// GEN-LAST:event_eficienciaVolumetricaFocusGained

	private void grauUtilizacaoHastesFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_grauUtilizacaoHastesFocusGained
		labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_hastes.png")));
	}// GEN-LAST:event_grauUtilizacaoHastesFocusGained

	private void custosColunaHastesFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_custosColunaHastesFocusGained
		labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_hastes.png")));
	}// GEN-LAST:event_custosColunaHastesFocusGained

	private void cargaMaxFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_cargaMaxFocusGained
		labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_estrutura.png")));
	}// GEN-LAST:event_cargaMaxFocusGained

	private void nivelVazaoFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_nivelVazaoFocusGained
		labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_bomba.png")));
	}// GEN-LAST:event_nivelVazaoFocusGained

	private void peakTorqueFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_peakTorqueFocusGained
		labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_redutor.png")));
	}// GEN-LAST:event_peakTorqueFocusGained

	private void frequenciaBombeioFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_frequenciaBombeioFocusGained
		labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_redutor.png")));
	}// GEN-LAST:event_frequenciaBombeioFocusGained

	private void avaliarButtonFocusGained(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_avaliarButtonFocusGained
		labelImagem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/ufabc/edu/logica/nao/classicas/imagens/img_nenhum.png")));
	}// GEN-LAST:event_avaliarButtonFocusGained

	/**
	 * Ação do evento Avaliar.
	 * 
	 * @param evt
	 *            event on click button Avaliar
	 */
	private void btnTODOSActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
		FunctionBlock functionBlock = fis.getFunctionBlock(null);
		double ev = Double.valueOf(this.jTextField1.getText());
		functionBlock.setVariable("EV", ev); // Eficiência Volumétrica [0..1]

		double nav = Double.valueOf(this.jTextField2.getText());
		functionBlock.setVariable("NAV", nav); // Nível de Atendimento de Vazão [0.95..1.5]

		double uh = Double.valueOf(this.jTextField3.getText());
		functionBlock.setVariable("UH", uh); // Grau de Utilização de Hastes [0..1]

		double ch = Double.valueOf(this.jTextField4.getText());
		functionBlock.setVariable("CH", ch); // Custo da Coluna de Hastes [0.3..2.0]

		double pt = Double.valueOf(this.jTextField5.getText());
		functionBlock.setVariable("PT", pt); // Peak de Torque [0..1]

		double fb = Double.valueOf(this.jTextField6.getText());
		functionBlock.setVariable("FB", fb); // Frequência de Bombeio [0..25]

		double cMax = Double.valueOf(this.jTextField7.getText());
		functionBlock.setVariable("CMax", cMax); // Carga Máxima [0..1]

		double cMin = Double.valueOf(this.jTextField8.getText());
		functionBlock.setVariable("CMin", cMin); // Carga Mínima [0..1]

		functionBlock.evaluate();

		setResultLabel(functionBlock, this.resultColunaHastes, "CDH");
		setResultLabel(functionBlock, this.resultBombaFundo, "BF");
		setResultLabel(functionBlock, this.resultBombeio, "UB");
		setResultLabel(functionBlock, this.resultSistemaBombeio, "SB");
	}

	private void setResultLabel(FunctionBlock functionBlock, JLabel resultLabel, String variavel) {
		double valorVariavel = functionBlock.getVariable(variavel).getValue();
		resultLabel.setText(String.format("%1$,.2f", valorVariavel));
		resultLabel.setForeground(getColorByValue(valorVariavel));
	}

	private Color getColorByValue(double value) {
		return new Color(this.getVermelho(value), this.getVerde(value), this.getAzul(value));
	}

	/**
	 * 
	 * @param valor
	 *            valor
	 * @return o valor que será inserido para a cor vermelha
	 */
	public int getVermelho(Double valor) {
		return (int) (((50.0 - Math.min(valor, 50.0)) / 50.0) * 255.0);
	}

	/**
	 * 
	 * @param valor
	 *            valor
	 * @return o valor que será inserido para a cor vermelha
	 */
	public int getVerde(Double valor) {
		return (int) (((Math.min(valor, 50.0) - (Math.max(valor, 50.0) - 50.0)) / 50.0) * 255);
	}

	/**
	 * 
	 * @param valor
	 *            valor
	 * @return o valor que será inserido para a cor vermelha
	 */
	public int getAzul(Double valor) {
		return (int) ((Math.max(valor - 50.0, 0) / 50.0) * 255);
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				new FramePrincipal().setVisible(true);
			}
		});
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBF;
    private javax.swing.JButton btnCDH;
    private javax.swing.JButton btnTODOS;
    private javax.swing.JButton btnUB;
    private javax.swing.JLabel imgPaletaCores;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JLabel labelImagem;
    private javax.swing.JLabel resultBombaFundo;
    private javax.swing.JLabel resultBombeio;
    private javax.swing.JLabel resultColunaHastes;
    private javax.swing.JLabel resultSistemaBombeio;
    // End of variables declaration//GEN-END:variables
}
